package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.neu.dao.ShoppingBrandMapper;
import com.neu.domain.ShoppingAdExample;
import com.neu.domain.ShoppingBrand;
import com.neu.domain.ShoppingBrand.Column;
import com.neu.domain.ShoppingBrandExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ShoppingBrandService {
	@Resource
	public ShoppingBrandMapper shoppingBrandMapper;
//	添加
	public void add(ShoppingBrand record) {
		record.setAddTime(LocalDateTime.now());
		record.setUpdateTime(LocalDateTime.now());
		shoppingBrandMapper.insertSelective(record);
	}
//
	public void deleteById(Integer id) {
		shoppingBrandMapper.logicalDeleteByPrimaryKey(id);
	}
	public int updateById(ShoppingBrand record) {
		record.setUpdateTime(LocalDateTime.now());	
		return shoppingBrandMapper.updateByPrimaryKeySelective(record);	
	}
	public List<ShoppingBrand> querySelective(String desc, String content, Integer page, Integer limit, String sort, String order){
		ShoppingBrandExample example = new ShoppingBrandExample();
		ShoppingBrandExample.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(desc)) {
            criteria.andDescLike("%" + desc + "%");
        }
        if (!StringUtils.isEmpty(content)) {
        	criteria.andContentLike("%" + content + "%");
        }
        criteria.andDeletedEqualTo(false);

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);
        return shoppingBrandMapper.selectByExample(example);
		
	}

	//查询品牌商信息
	public ShoppingBrand findById(Integer  id) {
		return shoppingBrandMapper.selectByPrimaryKey(id);
	}
	//查询品牌商信息
	public List<ShoppingBrand> all(){
		ShoppingBrandExample example =new ShoppingBrandExample();
		ShoppingBrandExample.Criteria ceiterion = example.createCriteria();
		example.or().andDeletedEqualTo(false);
		return shoppingBrandMapper.selectByExample(example);
	}

}
